package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.StudentBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface IStudentMapper extends BaseMapper<StudentBean> {


    IPage<StudentBean> findByItem(Page page, @Param("name") String name,@Param("className") String className, @Param("roomAddress") String roomAddress);


    @Delete("delete  from t_student where pk_studentId=#{id}")
    void del(Integer id);


    void add(StudentBean student);

    @Update("update t_student set fk_roomId=#{studentId} where pk_studentId=#{roomId}")
    void changeRoom(@Param("studentId")Integer studentId,@Param("roomId") Integer roomId);


    @Select("SELECT s.*,c.*,r.* FROM t_student s JOIN t_class c ON s.`fk_classId`=c.`pk_classId` JOIN t_room r ON r.`pk_roomId`=s.`fk_roomId` WHERE pk_studentId=#{id}")
    @ResultMap("studentMap")
    StudentBean findById(Integer id);


    @Select("select s.*,c.c_name from t_room r join t_student s on pk_roomId=fk_roomId join t_class c on pk_classId=fk_classId where pk_roomId=#{id}")
    @ResultMap("studentMap")
    List<StudentBean> findStudentByRoomId(Integer id);


}
